package com.example.myapplicationsenior;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private Button wxgb;
    private Button wxgb2;
    private Button yxgb;
    private Button dtgb;

    //动态广播
    private trendsMyReceiver trendsMyReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        wxgb = (Button) findViewById(R.id.wxgb);
        wxgb2 = (Button) findViewById(R.id.wxgb2);
        yxgb = (Button) findViewById(R.id.yxgb);
        dtgb = (Button) findViewById(R.id.dtgb);

        //创建动态广播
        trendsMyReceiver = new trendsMyReceiver();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.trends");
        registerReceiver(trendsMyReceiver,intentFilter);

        wxgb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction("com.liang1");
                sendBroadcast(intent);
            }
        });

        yxgb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction("com.youxu");
                sendOrderedBroadcast(intent,null);
            }
        });
        dtgb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction("com.trends");
                sendBroadcast(intent);
            }
        });
    }
}